package C;

import java.util.Arrays;
import java.util.Scanner;

public class C61 {

    static class Node{
        int value;
        Node prev;
        Node next;

        Node(int value) {
            this.value = value;
        }
    }

    static class CycleList {
        Node head;
        Node tail;
        int size=0;

        void add(int value) {
            Node node = new Node(value);
            if (this.size==0) {
                head = tail = node;
                head.next = head.prev = node;
                tail.next = tail.prev = node;
            } else {
                tail.next = node;
                head.prev = node;
                node.next = head;
                node.prev = tail;
                tail = node;
            }
            this.size++;
        }

        void remove(Node old) {
            //其实，size>=left>=1，所有remove时size最小是2
            if (this.size==0) {
                return;
            }
            if (this.size==1) {
                old.prev=old.next=null;
                this.head=this.tail=null;
                this.size--;
                return;
            }

            Node prev = old.prev;
            Node next = old.next;
            prev.next = next;
            next.prev = prev;
            old.next=old.prev=null;
            this.size--;
            if (old==this.head) {
                this.head = next;
            }
            if (old == this.tail) {
                this.tail = prev;
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        int jump = Integer.parseInt(sc.nextLine());
        int left = Integer.parseInt(sc.nextLine());
        System.out.println(getResult(nums,jump,left));
    }

    public static int getResult(int[] nums,int jump,int left) {
        int sum = 0;
        if (left==0) {
            return 0;
        }
        if (nums.length<=left) {
            for (int i = 0; i < nums.length; i++) {
                sum+=nums[i];
            }
            return sum;
        }
        CycleList cycleList = new CycleList();
        for (int num : nums) {
            cycleList.add(num);
        }
        Node cur = cycleList.head.next;
        int count=0;
        while(cycleList.size>left) {
            while(count!=jump) {
                cur = cur.next;
                count++;
            }
            count=0;
            Node next = cur.next;
            cycleList.remove(cur);
            cur = next;
        }
        cur = cycleList.head;
        for (int i=0;i<left;i++) {
            sum+=cur.value;
            cur = cur.next;
        }
        return sum;
    }
}
